package itheima_edu_info_manager.com.itheima.edu.info.manager.service;

import itheima_edu_info_manager.com.itheima.edu.info.manager.dao.TeacherDao;
import itheima_edu_info_manager.com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //判断输入的老师id是否存在
    public boolean isExists(String id) {
        boolean flag = false;
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null && teacher.getId().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    //删除老师
    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacherById(id);
    }

    //添加老师
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    //查询老师
    public Teacher[] findAllTeacher() {
        boolean flag = false;
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return teachers;
        } else {
            return null;
        }
    }

    //修改老师
    public void upDateTeacherById(String id, Teacher teacher) {
        teacherDao.upDateTeacherById(id,teacher);
    }
}
